require 'cgi'

module WPSpider
  module Common

    #
    # HTTP Response class.
    #
    class HttpResponse

      #
      # Constructor.
      #
      def initialize(cgi)
        @cgi = cgi
        @headers = Hash.new()
        @headers['cookie'] = Hash.new()
        @body = String.new()
      end

      #
      # Sets Content-Type
      # - type
      #
      def set_content_type(type)
        @headers['type'] = type
      end

      #
      # Gets Content-Type
      # - return
      #
      def get_content_type()
        return @headers['type']
      end

      #
      # Sets charset.
      # - charset
      #
      def set_charset(charset)
        @headers['charset'] = charset
      end

      #
      # Gets charset.
      # - return
      #
      def get_charset()
        return @headers['charset']
      end

      #
      # Sets cookie.
      # - name
      # - value
      # - path
      # - domain
      # - expires
      # - secure
      #
      def set_cookie(name, value, path = nil, domain = nil, expires = nil, secure = nil)
        cookie = Hash.new()
        cookie['name'] = name
        cookie['value'] = value
        cookie['path'] = path if(path)
        cookie['domain'] = path if(domain)
        cookie['expires'] = path if(expires)
        cookie['secure'] = path if(secure)
        @headers['cookie'][name] = CGI::Cookie.new(cookie)
      end

      #
      # Gets cookie.
      # - name
      # - return
      #
      def get_cookie(name)
      end

      #
      #
      #
      def set_header(name, val)
        @headers[name] = val
      end

      #
      #
      #
      def get_header(name)
        return @headers[name]
      end

      #
      #
      #
      def set_headers(headers)
        @headers = headers
      end

      #
      #
      #
      def get_headers()
        return @headers
      end

      #
      #
      #
      def set_body(body)
        @body = body
      end

      #
      #
      #
      def add_body(body)
        @body << body
      end

      #
      #
      #
      def get_body()
        return @body
      end
    end
  end
end
      
